package com.ruoyi.dev.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dev.domain.DevChart;
import com.ruoyi.dev.service.IDevChartService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报表Controller
 * 
 * @author yepanpan
 * @date 2024-12-23
 */
@RestController
@RequestMapping("/dev/chart")
public class DevChartController extends BaseController
{
    @Autowired
    private IDevChartService devChartService;

    /**
     * 查询报表列表
     */
    @PreAuthorize("@ss.hasPermi('dev:chart:list')")
    @GetMapping("/list")
    public TableDataInfo list(DevChart devChart)
    {
        startPage();
        List<DevChart> list = devChartService.selectDevChartList(devChart);
        return getDataTable(list);
    }

    /**
     * 导出报表列表
     */
    @PreAuthorize("@ss.hasPermi('dev:chart:export')")
    @Log(title = "报表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DevChart devChart)
    {
        List<DevChart> list = devChartService.selectDevChartList(devChart);
        ExcelUtil<DevChart> util = new ExcelUtil<DevChart>(DevChart.class);
        util.exportExcel(response, list, "报表数据");
    }

    /**
     * 获取报表详细信息
     */
    @PreAuthorize("@ss.hasPermi('dev:chart:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(devChartService.selectDevChartById(id));
    }

    /**
     * 新增报表
     */
    @PreAuthorize("@ss.hasPermi('dev:chart:add')")
    @Log(title = "报表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DevChart devChart)
    {
        return toAjax(devChartService.insertDevChart(devChart));
    }

    /**
     * 修改报表
     */
    @PreAuthorize("@ss.hasPermi('dev:chart:edit')")
    @Log(title = "报表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DevChart devChart)
    {
        return toAjax(devChartService.updateDevChart(devChart));
    }

    /**
     * 删除报表
     */
    @PreAuthorize("@ss.hasPermi('dev:chart:remove')")
    @Log(title = "报表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(devChartService.deleteDevChartByIds(ids));
    }


    /**
     * 获取报表详细信息
     */
    @GetMapping(value = "/info/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(devChartService.selectDevChartByCode(code));
    }

    /**
     * 报表详添加到菜单
     */
    @GetMapping(value = "/menu/{id}")
    public AjaxResult addMenu(@PathVariable("id") Long id)
    {
        return success(devChartService.addDevChartMenu(id));
    }
}
